Skip to content

perf: don't drop rust compiler instance in non-watch mode#11920

Merged
hardfist merged 3 commits intomainfrom
yj/no-drop-compiler
Oct 20, 2025
Merged

perf: don't drop rust compiler instance in non-watch mode#11920
hardfist merged 3 commits intomainfrom
yj/no-drop-compiler

Conversation

@hardfist
Copy link
Contributor

@hardfist hardfist commented Oct 20, 2025

Summary

It's slow and unnecessary to drop the Compiler & Compilation in non-watch mode, so support to ignore drop of Compiler & Compilation instance in non-watch mode

img_v3_02r8_bfcdbf08-bf59-4d3b-bfd5-158e9fd89eeg

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@netlify
Copy link

netlify bot commented Oct 20, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit efa8399
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/68f5c11f2ef2f00008d88b9f

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: performance release: performance related release(mr only) labels Oct 20, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

📝 Benchmark detail: Open

Name Base (2025-10-20 beafb11) Current Change
10000_big_production-mode_disable-minimize + exec 27.7 s ± 417 ms 27.7 s ± 1.19 s +0.05 %
10000_development-mode + exec 1.61 s ± 6 ms 1.38 s ± 37 ms -14.67 %
10000_development-mode_hmr + exec 670 ms ± 3 ms 666 ms ± 8.3 ms -0.67 %
10000_development-mode_noop-loader + exec 2.56 s ± 107 ms 2.32 s ± 47 ms -9.32 %
10000_production-mode + exec 1.6 s ± 12 ms 1.48 s ± 144 ms -7.76 %
10000_production-mode_persistent-cold + exec 1.79 s ± 38 ms 1.63 s ± 61 ms -8.89 %
10000_production-mode_persistent-hot + exec 1.36 s ± 105 ms 1.2 s ± 38 ms -11.50 %
arco-pro_development-mode + exec 1.62 s ± 60 ms 1.66 s ± 219 ms +2.50 %
arco-pro_development-mode_hmr + exec 376 ms ± 2.5 ms 375 ms ± 2.9 ms -0.43 %
arco-pro_production-mode + exec 3.14 s ± 75 ms 3.06 s ± 183 ms -2.60 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.2 s ± 99 ms 3.1 s ± 83 ms -3.12 %
arco-pro_production-mode_persistent-cold + exec 3.22 s ± 86 ms 3.16 s ± 69 ms -1.91 %
arco-pro_production-mode_persistent-hot + exec 1.87 s ± 63 ms 1.87 s ± 181 ms -0.46 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.17 s ± 94 ms 3.09 s ± 63 ms -2.50 %
large-dyn-imports_development-mode + exec 1.89 s ± 48 ms 1.63 s ± 43 ms -13.68 %
large-dyn-imports_production-mode + exec 1.85 s ± 27 ms 1.66 s ± 49 ms -10.12 %
threejs_development-mode_10x + exec 1.44 s ± 102 ms 1.36 s ± 126 ms -5.64 %
threejs_development-mode_10x_hmr + exec 916 ms ± 17 ms 915 ms ± 29 ms -0.15 %
threejs_production-mode_10x + exec 4.42 s ± 38 ms 4.34 s ± 94 ms -1.84 %
threejs_production-mode_10x_persistent-cold + exec 4.53 s ± 34 ms 4.48 s ± 51 ms -1.01 %
threejs_production-mode_10x_persistent-hot + exec 4.06 s ± 195 ms 3.99 s ± 194 ms -1.71 %
10000_big_production-mode_disable-minimize + rss memory 8723 MiB ± 406 MiB 8600 MiB ± 540 MiB -1.41 %
10000_development-mode + rss memory 736 MiB ± 18.4 MiB 738 MiB ± 21.2 MiB +0.26 %
10000_development-mode_hmr + rss memory 902 MiB ± 10.7 MiB 894 MiB ± 16.7 MiB -0.84 %
10000_development-mode_noop-loader + rss memory 1051 MiB ± 31.5 MiB 1031 MiB ± 30.8 MiB -1.86 %
10000_production-mode + rss memory 650 MiB ± 17.5 MiB 651 MiB ± 10.1 MiB +0.11 %
10000_production-mode_persistent-cold + rss memory 817 MiB ± 16.9 MiB 826 MiB ± 65.2 MiB +1.04 %
10000_production-mode_persistent-hot + rss memory 815 MiB ± 23 MiB 811 MiB ± 27 MiB -0.43 %
arco-pro_development-mode + rss memory 543 MiB ± 44.2 MiB 547 MiB ± 63.3 MiB +0.78 %
arco-pro_development-mode_hmr + rss memory 446 MiB ± 33.9 MiB 436 MiB ± 16.8 MiB -2.30 %
arco-pro_production-mode + rss memory 659 MiB ± 54.3 MiB 669 MiB ± 95.7 MiB +1.52 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 718 MiB ± 65.2 MiB 663 MiB ± 98.8 MiB -7.66 %
arco-pro_production-mode_persistent-cold + rss memory 790 MiB ± 90 MiB 775 MiB ± 29.3 MiB -1.85 %
arco-pro_production-mode_persistent-hot + rss memory 561 MiB ± 95 MiB 580 MiB ± 143 MiB +3.31 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 656 MiB ± 68 MiB 652 MiB ± 66.8 MiB -0.61 %
large-dyn-imports_development-mode + rss memory 777 MiB ± 12 MiB 771 MiB ± 13.9 MiB -0.80 %
large-dyn-imports_production-mode + rss memory 623 MiB ± 7.23 MiB 619 MiB ± 16.2 MiB -0.60 %
threejs_development-mode_10x + rss memory 572 MiB ± 23 MiB 575 MiB ± 12.5 MiB +0.62 %
threejs_development-mode_10x_hmr + rss memory 813 MiB ± 87.2 MiB 827 MiB ± 55.7 MiB +1.73 %
threejs_production-mode_10x + rss memory 742 MiB ± 164 MiB 837 MiB ± 133 MiB +12.73 %
threejs_production-mode_10x_persistent-cold + rss memory 828 MiB ± 18.5 MiB 825 MiB ± 24.3 MiB -0.43 %
threejs_production-mode_10x_persistent-hot + rss memory 693 MiB ± 33.5 MiB 682 MiB ± 29.4 MiB -1.47 %

@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

📦 Binary Size-limit

Comparing efa8399 to test: add warn while closing compiler with failure (#11909) by harpsealjs

❌ Size increased by 640bytes from 47.67MB to 47.67MB (⬆️0.00%)

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 20, 2025

CodSpeed Performance Report

Merging #11920 will not alter performance

Comparing yj/no-drop-compiler (efa8399) with main (ceb5a7e)1

Summary

✅ 17 untouched

Footnotes

  1. No successful run was found on main (02ab3a4) during the generation of this report, so ceb5a7e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

📝 Benchmark detail: Open

Name Base (2025-10-20 beafb11) Current Change
10000_big_production-mode_disable-minimize + exec 27.7 s ± 417 ms 27.9 s ± 1.21 s +0.99 %
10000_development-mode + exec 1.61 s ± 6 ms 1.35 s ± 11 ms -16.26 %
10000_development-mode_hmr + exec 670 ms ± 3 ms 665 ms ± 3.5 ms -0.75 %
10000_development-mode_noop-loader + exec 2.56 s ± 107 ms 2.31 s ± 44 ms -9.89 %
10000_production-mode + exec 1.6 s ± 12 ms 1.48 s ± 94 ms -7.72 %
10000_production-mode_persistent-cold + exec 1.79 s ± 38 ms 1.62 s ± 43 ms -9.95 %
10000_production-mode_persistent-hot + exec 1.36 s ± 105 ms 1.2 s ± 21 ms -11.65 %
arco-pro_development-mode + exec 1.62 s ± 60 ms 1.65 s ± 54 ms +1.59 %
arco-pro_development-mode_hmr + exec 376 ms ± 2.5 ms 374 ms ± 2.7 ms -0.57 %
arco-pro_production-mode + exec 3.14 s ± 75 ms 3.07 s ± 95 ms -2.35 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.2 s ± 99 ms 3.11 s ± 64 ms -2.65 %
arco-pro_production-mode_persistent-cold + exec 3.22 s ± 86 ms 3.18 s ± 200 ms -1.42 %
arco-pro_production-mode_persistent-hot + exec 1.87 s ± 63 ms 1.83 s ± 87 ms -2.12 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.17 s ± 94 ms 3.05 s ± 43 ms -3.65 %
large-dyn-imports_development-mode + exec 1.89 s ± 48 ms 1.65 s ± 152 ms -12.73 %
large-dyn-imports_production-mode + exec 1.85 s ± 27 ms 1.67 s ± 32 ms -9.91 %
threejs_development-mode_10x + exec 1.44 s ± 102 ms 1.34 s ± 26 ms -7.16 %
threejs_development-mode_10x_hmr + exec 916 ms ± 17 ms 916 ms ± 29 ms -0.04 %
threejs_production-mode_10x + exec 4.42 s ± 38 ms 4.39 s ± 237 ms -0.75 %
threejs_production-mode_10x_persistent-cold + exec 4.53 s ± 34 ms 4.55 s ± 348 ms +0.38 %
threejs_production-mode_10x_persistent-hot + exec 4.06 s ± 195 ms 3.99 s ± 190 ms -1.61 %
10000_big_production-mode_disable-minimize + rss memory 8723 MiB ± 406 MiB 8776 MiB ± 310 MiB +0.60 %
10000_development-mode + rss memory 736 MiB ± 18.4 MiB 740 MiB ± 8.63 MiB +0.58 %
10000_development-mode_hmr + rss memory 902 MiB ± 10.7 MiB 897 MiB ± 13.6 MiB -0.56 %
10000_development-mode_noop-loader + rss memory 1051 MiB ± 31.5 MiB 1042 MiB ± 16.7 MiB -0.84 %
10000_production-mode + rss memory 650 MiB ± 17.5 MiB 655 MiB ± 37.2 MiB +0.75 %
10000_production-mode_persistent-cold + rss memory 817 MiB ± 16.9 MiB 825 MiB ± 37.4 MiB +1.01 %
10000_production-mode_persistent-hot + rss memory 815 MiB ± 23 MiB 814 MiB ± 10.1 MiB -0.13 %
arco-pro_development-mode + rss memory 543 MiB ± 44.2 MiB 542 MiB ± 62.4 MiB -0.21 %
arco-pro_development-mode_hmr + rss memory 446 MiB ± 33.9 MiB 436 MiB ± 7.05 MiB -2.32 %
arco-pro_production-mode + rss memory 659 MiB ± 54.3 MiB 683 MiB ± 84 MiB +3.56 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 718 MiB ± 65.2 MiB 672 MiB ± 88.7 MiB -6.50 %
arco-pro_production-mode_persistent-cold + rss memory 790 MiB ± 90 MiB 775 MiB ± 58.5 MiB -1.87 %
arco-pro_production-mode_persistent-hot + rss memory 561 MiB ± 95 MiB 573 MiB ± 86.6 MiB +2.09 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 656 MiB ± 68 MiB 638 MiB ± 89.3 MiB -2.72 %
large-dyn-imports_development-mode + rss memory 777 MiB ± 12 MiB 772 MiB ± 13.8 MiB -0.74 %
large-dyn-imports_production-mode + rss memory 623 MiB ± 7.23 MiB 619 MiB ± 5.33 MiB -0.56 %
threejs_development-mode_10x + rss memory 572 MiB ± 23 MiB 573 MiB ± 18.5 MiB +0.16 %
threejs_development-mode_10x_hmr + rss memory 813 MiB ± 87.2 MiB 798 MiB ± 57.9 MiB -1.93 %
threejs_production-mode_10x + rss memory 742 MiB ± 164 MiB 774 MiB ± 224 MiB +4.24 %
threejs_production-mode_10x_persistent-cold + rss memory 828 MiB ± 18.5 MiB 825 MiB ± 44.8 MiB -0.34 %
threejs_production-mode_10x_persistent-hot + rss memory 693 MiB ± 33.5 MiB 684 MiB ± 31.3 MiB -1.25 %

@hardfist hardfist force-pushed the yj/no-drop-compiler branch from 7df0084 to efa8399 Compare October 20, 2025 04:57
@hardfist hardfist marked this pull request as ready for review October 20, 2025 05:16
Copilot AI review requested due to automatic review settings October 20, 2025 05:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes non-watch builds by avoiding costly Rust compiler teardown. It introduces an internal unsafeFastDrop flag that propagates from the CLI to the Rust binding, conditionally skipping drop in finalize to improve performance.

  • Add internal unsafeFastDrop flag to Compiler and a setter on MultiCompiler; CLI sets it when not in watch mode
  • Update Rust binding to wrap Compiler in ManuallyDrop and conditionally drop in finalize based on the flag

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/rspack/src/MultiCompiler.ts Adds a setter to propagate unsafeFastDrop to child compilers
packages/rspack/src/Compiler.ts Adds unsafeFastDrop property and forwards it into the native binding constructor
packages/rspack/etc/core.api.md Updates API report for new internal field/setter
packages/rspack-cli/src/cli.ts Sets unsafeFastDrop in non-watch mode to skip drop overhead
crates/rspack_binding_api/src/lib.rs Wraps Compiler in ManuallyDrop and conditionally drops in finalize
Comments suppressed due to low confidence (1)

crates/rspack_binding_api/src/lib.rs:1

  • self.compiler is ManuallyDrop; calling methods directly on it will not compile. Obtain a reference to the inner Compiler (e.g., via as_ptr) before calling id(). For example: let compiler_ref: &Compiler = unsafe { &*self.compiler.as_ptr() }; let compiler_id = compiler_ref.id();
#![recursion_limit = "256"]

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@SyMind
Copy link
Member

SyMind commented Oct 20, 2025

should we need move the option into experiments?

Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@hardfist hardfist merged commit e56ad1f into main Oct 20, 2025
91 of 96 checks passed
@hardfist hardfist deleted the yj/no-drop-compiler branch October 20, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: performance release: performance related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants